package com.songshu.sca.nacosConfig;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 使用@Value方式读取nacos配置
 */
@Configuration
@Component
@Slf4j
@RefreshScope
public class NacosConfigTest {

    @Value("${db.url}")
    private String db_url;

    @Value("${db.username}")
    private String db_username;

    @Value("${db.password}")
    private String db_password;


    public String getDb_url() {
        return db_url;
    }

    public void setDb_url(String db_url) {
        this.db_url = db_url;
    }

    public String getDb_username() {
        return db_username;
    }

    public void setDb_username(String db_username) {
        this.db_username = db_username;
    }

    public String getDb_password() {
        return db_password;
    }

    public void setDb_password(String db_password) {
        this.db_password = db_password;
    }

    @Override
    public String toString() {
        return "NacosConfigTest{" +
                "db_url='" + db_url + '\'' +
                ", db_username='" + db_username + '\'' +
                ", db_password='" + db_password + '\'' +
                '}';
    }

    @PostConstruct
    public void printConfig(){
        log.info("读取nacos配置文件内容如下： {}, {}, {}", db_url, db_username, db_password);
    }

}
